<%@page import="com.rivercloud.entity.UserVo"%>
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<html>
<head>
<base href="<%=basePath%>">
<title>项目信息</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="${base}/css/bootstrap.css">
<link rel="stylesheet" type="text/css"
	href="${base}/css/jquery.searchableSelect.css">
<script type="text/javascript" src="${base}/js/jquery-3.1.0.js"></script>
<script type="text/javascript" src="${base}/js/bootstrap.js"></script>
<script type="text/javascript"
	src="${base}/js/jquery.searchableSelect.js"></script>


<script>


	$(function() {
		
		$('#memberName').searchableSelect();
		

	});
	
	
	function addProjectDesc(){
		$.ajax({  
            type: "POST",  
            url:"${base}/project/addProjectDesc",  
            data:$('#myForm1').serialize(),// 序列化表单值  
            dataType: "json",
            success: function (data) {
                location.reload();
                location.location;
			},
			async: true,
			cache: false
			}); 
       
	}
	
	
	function addMember(){
		$.ajax({  
            type: "POST",  
            url:"${base}/project/addMember",  
            data:$('#myForm').serialize(),// 序列化表单值  
            dataType: "json",
            success: function (data) {
                location.location;
			},
			async: true,
			cache: false
			}); 
       
	}
	
	function deleteMember(projectId,userId,i) {
	    /* alert(obj1);
	    alert(obj2); */
	   if(table.rows.length == 2){
		  alert("项目成员太少，已不能继续删除，请尝试添加成员~");
	   }else{
	    if (confirm("确认删除该成员吗？")){
			$.ajax({
				url: "${base}/project/deleteMember",
				data: {projectId:projectId,userId:userId},
				dataType: "json",
				type: "POST",
				success: function (data) {
					if(data == 1){
						alert("删除成功");
		                location.reload();	
					}else if(data == 2){
						alert("该成员存在关联数据，不能删除");
					}
					
				},
				async: true,
				cache: false
				});
	    }
	   }
	}
</script>
</head>

<body>
	<div class="container">
		<jsp:include page="${path}/menu.jsp"></jsp:include>
		<div style="margin-left: 20px;margin-bottom: 10px; color: grey">当前位置：项目管理 > ${project.projectName } 项目</div>
		<div class="container-fluid">
			<div class="row-fluid">
			
				<div class="col-md-4">
				<font size="4"  style="width: 300px;"><b>项目名称：${project.projectName }</b></font>
				</div>
				<div class="col-md-4">
				<font size="4" style="width: 300px;"><b>项目经理：
					${project.managerName }</b></font>
				</div>
				<div class="col-md-4" >
				<font size="4"  style="width: 300px;"><b>项目人数：${project.memberNum+1 }</b></font>
				</div>
				<br/>
				<div class="span12" style="padding-top: 20px; padding-bottom: 20px">
					<font size="3" style="width: 300px;">项目描述：${project.projectDesc }</font>
				</div>

				<div class="span12">

					

					<c:if test="${!empty userList}">
						<table class="table" id="table">
							<thead>
							<!-- alan_18.3.2_style_update -->
								<tr class="tr" style="background-color:#87CEEB;">
									<th><input type="checkbox" id="selectAll"></th>
									<th>项目成员</th>
									<th>邮箱</th>
									
									<th>操作</th>
								</tr>
							</thead>
							<%-- <c:if test="${empty tableList}">
								<h4>
									<span style="color: red;">列表为空,暂无文件</span>
									<a href="${base}/createTable.jsp">新建表格</a>
								</h4>
							</c:if> --%>
							<tbody>



								<c:forEach items="${userList}" var="member" varStatus="i">
									<tr class="tr">
										<%-- <td><a href="${pageContext.request.contextPath}/template.jsp">${template.templateName }</a></td> --%>
										<td><input type="checkbox" name="ids"></td>
										<td>${member.name}</td>
										<td>${member.email}</td>

									<%-- 	<td><button class="btn btn-danger btn-sm delete" 
												onclick="deleteMember(${project.id},${user.id })">delete</button></td> --%>
												
												<td><c:set scope="page" value="member" var="pageDelete"></c:set>
												<c:set scope="page" value="manager" var="pagein"></c:set>
										<!-- 为每个要判断的按钮或者功能定义一个变量，对应数据库后台的权限表中的keyword字段 -->
										<c:if test="${project.managerName == user.name}">

											<button class="btn btn-danger btn-sm" onclick="deleteMember(${project.id},${member.id },${i.index})">delete</button>
										</c:if> 
										</td>
									</tr>
								</c:forEach>


							</tbody>
						</table>
					</c:if>

					<div class="container">
					<c:set scope="page" value="add_member" var="pageAdd"></c:set>
										<!-- 为每个要判断的按钮或者功能定义一个变量，对应数据库后台的权限表中的keyword字段 -->
									<%-- 	 <% 
											  String pageDelete=(String)pageContext.getAttribute("pageAdd");
											  //然后改变这里取出来
											  
											  UserVo userVo=(UserVo)session.getAttribute("userVo");
											  String keyword=userVo.getpKeyword();
											  System.out.println(keyword);
											 String [] keywords=keyword.split(",");
												  Boolean flag=false;
												  if(keywords.length>1){
													  flag=keyword.contains(pageDelete);//这里改变
												  }else{
													  flag=keyword.equals(pageDelete);//这里改变，最后就能实现了
												  }
												  System.out.println(userVo.getuName()+"权限为："+flag);
												   if(flag){
											%>
											
 --%>
 
 									<c:set scope="page" value="manager" var="pagein"></c:set>
										<!-- 为每个要判断的按钮或者功能定义一个变量，对应数据库后台的权限表中的keyword字段 -->
						<c:if test="${project.managerName == user.name}">
							
							<button class="btn btn-primary" data-toggle="modal"
								data-target="#myModal">添加成员</button>
							<!--  定义模态框触发器，此处为按钮触发  -->
							
							<button class="btn btn-primary" data-toggle="modal"
								data-target="#myModal1">添加项目描述</button>
							<!--  定义模态框触发器，此处为按钮触发  -->
					 	</c:if>
					

						<form method="post" action="" class="form-horizontal" role="form"
							id="myForm" onsubmit="return ">
							<div class="modal fade" id="myModal" role="dialog" tabindex=-1
								aria-labelledby="myModalLabel" aria-hidden="true">
								<!--  定义模态框，过渡效果为淡入，id为myModal,tabindex=-1可以禁用使用tab切换，aria-labelledby用于引用模态框的标题，aria-hidden=true保持模态框在触发前窗口不可见  -->
								<div class="modal-dialog">
									<!--  显示模态框对话框模型（若不写下一个div则没有颜色）  -->
									<div class="modal-content">
										<!--  显示模态框白色背景，所有内容都写在这个div里面  -->

										<div class="btn-info modal-header">
											<!--  模态框标题  -->
											<button type="button" class="close" data-dismiss="modal">&times;</button>
											<!--  关闭按钮  -->
											<h4>添加成员</h4>
											<!--  标题内容  -->
										</div>

										<div class="modal-body">
											<!--  模态框内容，我在此处添加一个表单 -->
											<form class="form-horizontal" role="form">
												<div class="form-group">
													<label for="memberName" class="col-sm-2 control-label">成员姓名:</label>
													<div class="col-sm-6">
														<input type="hidden" name="projectId" value="${project.id }">
														<select  id="memberName" name="memberName">
														
															<option value="">请选择或者输入成员姓名</option>
															<c:forEach items="${users}" var="user">
																<option value="${user.name }">${user.name }</option>
															</c:forEach>
														</select>
													</div>
												</div>

											</form>
										</div>

										<div class="modal-footer">
											<!--  模态框底部样式，一般是提交或者确定按钮 -->
											<button  class="btn btn-info" onclick="addMember()" >确定</button>
											<button type="button" class="btn btn-default"
												data-dismiss="modal">取消</button>
										</div>

									</div>
									<!-- /.modal-content -->
								</div>
							</div>
							<!-- /.modal -->
						</form>

						<form method="post" action="" class="form-horizontal" role="form"
							id="myForm1" onsubmit="return ">
							<div class="modal fade" id="myModal1" role="dialog" tabindex=-1
								aria-labelledby="myModalLabel" aria-hidden="true">
								<!--  定义模态框，过渡效果为淡入，id为myModal,tabindex=-1可以禁用使用tab切换，aria-labelledby用于引用模态框的标题，aria-hidden=true保持模态框在触发前窗口不可见  -->
								<div class="modal-dialog">
									<!--  显示模态框对话框模型（若不写下一个div则没有颜色）  -->
									<div class="modal-content">
										<!--  显示模态框白色背景，所有内容都写在这个div里面  -->

										<div class="btn-info modal-header">
											<!--  模态框标题  -->
											<button type="button" class="close" data-dismiss="modal">&times;</button>
											<!--  关闭按钮  -->
											<h4>添加项目描述</h4>
											<!--  标题内容  -->
										</div>

										<div class="modal-body">
											<!--  模态框内容，我在此处添加一个表单 -->
											<form class="form-horizontal" role="form">
												<div class="form-group">
													<label for="projectDesc" class="col-sm-2 control-label">项目描述:</label>
													<div class="col-sm-6">
														<input type="hidden" name="projectId" value="${project.id }"/>
														
														<input type="text" id="projectDesc" name="projectDesc"
															class="form-control well" placeholder="请用一句话描述该项目" />
													</div>
												</div>

											</form>
										</div>

										<div class="modal-footer">
											<!--  模态框底部样式，一般是提交或者确定按钮 -->
											<button  class="btn btn-info" onclick="addProjectDesc()" >确定</button>
											<button type="button" class="btn btn-default"
												data-dismiss="modal">取消</button>
										</div>

									</div>
									<!-- /.modal-content -->
								</div>
							</div>
							<!-- /.modal -->
						</form>
					</div>

				</div>
			</div>
		</div>
	</div>
</body>

</html>


